package com.hevery.blog.common.util;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: ${web工具类}
 * @author: hongyu.zhang
 * @create: 2018-04-03
 **/
public class WebUtil {

    /**
     * 判断是否为Ajax请求
     * @param request
     * @return
     */
    public static boolean isAjaxRequest(HttpServletRequest request){
        String resultType = request.getHeader("X-Requested-With");
        String uri =  request.getRequestURI();
        boolean isJson = (resultType != null && "XMLHttpRequest".equals(resultType)) || uri.endsWith(".json");
        if(isJson){
            return true;
        }
        return false;
    }
}
